# coding: utf-8

from flask import Blueprint, render_template
from app.utils import helper

files = Blueprint('files', __name__)


# 文件列表
@files.route('/func_list/files_list/', methods=['GET', 'POST'])
def files_list():
    data_list = helper.fetch_all("SELECT id, file_name, target_path, insert_time FROM files_upload", [])
    return render_template('func_list/files_list.html', data_list=data_list)


# 上传文件统计页
@files.route('/func_list/files_detail/<int:nid>')
def files_detail(nid):
    record_list = helper.fetch_all(
        "SELECT id, line, ctime, note_line, blank_line, actual_line, actual_line_rate, note_line_rate, blank_line_rate,"
        "file_name FROM record where file_id=%s",
        (nid,))
    print("record_list", record_list)
    files_id = helper.fetch_one("SELECT user_id FROM files_upload WHERE id=%s", (nid,))
    user_name = helper.fetch_one("SELECT nickname FROM user_info WHERE id=%s", (files_id['user_id'],))
    return render_template('func_list/files_detail.html', record_list=record_list, user_name=user_name)
